import 'package:flutter/material.dart';

class LoginForm extends StatefulWidget {
  @override
  _LoginFormState createState() => _LoginFormState();
}

class _LoginFormState extends State<LoginForm> {
  final _formKey = GlobalKey<FormState>(); //???
  Widget _button(context) {
    return Center(
      child: ElevatedButton(
        onPressed: () => {
          if (_formKey.currentState.validate())
            {Navigator.pushNamed(context, '/home', arguments: '1234')}
        },
        child: Text('确认'),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Center(
        child: Container(
          padding:const EdgeInsets.all(20.0),
      width: 300,
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(8.0),
        boxShadow: [
          BoxShadow(
            color:Colors.black12,
            offset:Offset(0.0,15.0),//阴影x、y轴偏移量
            blurRadius:15.0,//阴影模糊程度
            spreadRadius: 1.0//阴影扩散程度
          )
        ]
      ),
      child: Form(
          key: _formKey,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              TextFormField(
                decoration: const InputDecoration(hintText: '请输入账号'),
                validator: (value) {
                  if (value.isEmpty) {
                    return '账号不可为空';
                  }
                  return null;
                },
              ),
              TextFormField(
                decoration: const InputDecoration(hintText: '请输入密码'),
                validator: (value) {
                  if (value.isEmpty) {
                    return '密码不可为空';
                  }
                  return null;
                },
              ),
              Padding(
                padding: const EdgeInsets.symmetric(vertical: 16.0),
                child: _button(context),
              )
            ],
          )),
    ));
  }
}
